package com.leyou.Search.controller;

import com.leyou.Search.service.SearchService;
import com.leyou.Search.utils.SearchRequest;
import com.leyou.Search.utils.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: taft
 * @Date: 2018-11-22 12:21
 */
@RestController
public class SearchController {

    @Autowired
    private SearchService searchService;

    @PostMapping("page")
    public ResponseEntity<SearchResult> page(@RequestBody SearchRequest searchRequest){


            SearchResult pageResult = searchService.pageQuery(searchRequest);

            if (pageResult != null && 0!=pageResult.getItems().size()) {
                return ResponseEntity.ok(pageResult);
            }
            return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
        }
}
